﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;

namespace WebClass
{
    public class CacheHelper
    {
        private static Cache m_cache = null;
        private static Cache Cache
        {
            get
            {
                if (m_cache == null)
                {
                    lock (typeof(CacheHelper))
                    {
                        if (m_cache == null)
                        {
                            m_cache = new Cache();
                        }
                    }
                }

                return m_cache;
            }
        }

        public static T Get<T>(string key)
        {
            var obj = Cache.Get(key);
            T value = (T)obj;

            return value;
        }

        public static void Set(string key, object value)
        {
            Set(key, value, 15);
        }

        public static void Set(string key, object value, int minute)
        {
            Cache.Add(key, value, null, DateTime.Now.AddMinutes(minute), new TimeSpan(20), CacheItemPriority.High, null);
        }
    }
}
